package com.haierp.service.bi.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.framework.service.impl.SuperServiceImpl;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.haierp.mapper.bi.BiShipMapper;
import com.haierp.mapperBi.BiDeliverGoodsMapper;
import com.haierp.mapperBi.BiDeliverPersonMapper;
import com.haierp.mapperBi.BiDeliverPrescriptionMapper;
import com.haierp.mapperBi.BiLogisticAvgtimeMapper;
import com.haierp.mapperBi.BiPackagePersonMapper;
import com.haierp.mapperBi.BiSaleInputPersonMapper;
import com.haierp.mapperBi.TaskNostockupReportMapper;
import com.haierp.model.bi.BiDeliverGoods;
import com.haierp.model.bi.BiDeliverPerson;
import com.haierp.model.bi.BiDeliverPrescription;
import com.haierp.model.bi.BiLogisticAvgtime;
import com.haierp.model.bi.BiPackagePerson;
import com.haierp.model.bi.BiSaleInputPerson;
import com.haierp.model.bi.BiShip;
import com.haierp.model.bi.TaskNostockupReport;
import com.haierp.service.bi.IBiShipService;
import com.haierp.util.DateUtil;



@Service("biShipService")
public class BiShipServiceImpl extends SuperServiceImpl<BiShipMapper, BiShip> implements IBiShipService {
	@Autowired
	private BiShipMapper biShipMapper;
	@Autowired
	private BiDeliverGoodsMapper biDeliverGoodsMapper;
	@Autowired
	private BiDeliverPrescriptionMapper biDeliverPrescriptionMapper;
	@Autowired
	private BiSaleInputPersonMapper biSaleInputPersonMapper;
	@Autowired
	private BiDeliverPersonMapper biDeliverPersonMapper;
	@Autowired
	private BiPackagePersonMapper biPackagePersonMapper;
	@Autowired
	private BiLogisticAvgtimeMapper biLogisticAvgtimeMapper;
	@Autowired
	private TaskNostockupReportMapper taskNostockupReport;
	@Override
	public List<BiDeliverGoods> selectBiShipReportByGmtCreate(Long companyId) {
		EntityWrapper<BiDeliverGoods> entityWrapper = new EntityWrapper<>();
		entityWrapper.where("company_id={0}", companyId);
		entityWrapper.addFilter("dimension_date<{0}", DateUtil.formatSimpleDate(DateUtil.getDateLeft(new Date(), -6)));
		entityWrapper.orderBy("dimension_date", false);
		return	biDeliverGoodsMapper.selectList(entityWrapper);
	}
	
	@Override
	public List<BiShip> selectBiShipReportExcelByGmtCreate() {

		return	biShipMapper.selectBiShipReportExcelByGmtCreate();
	}

	@Override
	public List<BiPackagePerson> selectBiShipPackerReportByPackageTime(Long companyId) {
		EntityWrapper<BiPackagePerson> entityWrapper = new EntityWrapper<>();
		entityWrapper.where("company_id={0}", companyId);
		entityWrapper.addFilter("dimension_date<{0}", DateUtil.formatSimpleDate(DateUtil.getDateLeft(new Date(), -6)));
		entityWrapper.orderBy("dimension_date", false);
		return biPackagePersonMapper.selectList(entityWrapper);
	}

	@Override
	public List<BiDeliverPerson> selectBiShipDeliveryReportByGmtCreate(Long companyId) {
		EntityWrapper<BiDeliverPerson> entityWrapper = new EntityWrapper<>();
		entityWrapper.where("company_id={0}", companyId);
		entityWrapper.addFilter("dimension_date<{0}", DateUtil.formatSimpleDate(DateUtil.getDateLeft(new Date(), -6)));
		entityWrapper.orderBy("dimension_date", false);
		return biDeliverPersonMapper.selectList(entityWrapper);
	}

	@Override
	public List<BiShip> selectBiShipDeliveryReportBySalesName(Long companyId) {

		return biShipMapper.selectBiShipDeliveryReportBySalesName(companyId);
	}

	@Override
	public List<BiShip> selectBiShipDeliveryReportBySalesNameMouth(Long companyId) {

		return biShipMapper.selectBiShipDeliveryReportBySalesNameMouth(companyId);
	}

	@Override
	public List<BiShip> selectBiSellerName(Long companyId) {

		return biShipMapper.selectBiSellerName(companyId);
	}
	@Override
	public List<BiShip> selectBiShipDeliveryReportByMouth(BiShip biShip) {

		return biShipMapper.selectBiShipDeliveryReportByMouth(biShip);
	}

	@Override
	public List<BiSaleInputPerson> selectBiShipDeliveryReportByUserCreate(Long companyId) {
		List<BiSaleInputPerson> listCurrent= biShipMapper.selectBiShipDeliveryReportByUserCreate(companyId);

		EntityWrapper<BiSaleInputPerson> entityWrapper = new EntityWrapper<>();
		entityWrapper.where("company_id={0}", companyId);
		entityWrapper.addFilter("dimension_date<{0}", DateUtil.formatSimpleDate(DateUtil.getDateLeft(new Date(), 0)));
		entityWrapper.orderBy("dimension_date", false);
		List<BiSaleInputPerson> list = biSaleInputPersonMapper.selectList(entityWrapper);

		list.addAll(0, listCurrent);
		return list;
	}

	@Override
	public List<BiShip> selectBiShipDeliveryReportByMouthOne(BiShip biShip) {

		return biShipMapper.selectBiShipDeliveryReportByMouthOne(biShip);
	}

	@Override
	public List<TaskNostockupReport> selectBiShiPNoStockReportByDate(Long companyId) {
		return taskNostockupReport.selectBiShiPNoStockReportByDate(companyId);
	}

	@Override
	public BiShip selectBiShiPNoStockVolumeReport(Long companyId) {
		return biShipMapper.selectBiShiPNoStockVolumeReport(companyId);
	}

	@Override
	public List<BiShip> selectPxImproperReport(BiShip biShip) {
		return biShipMapper.selectPxImproperReport(biShip);
	}

	@Override
	public List<BiLogisticAvgtime> selectShippingReportAvg(Long companyId) {
		EntityWrapper<BiLogisticAvgtime> entityWrapper = new EntityWrapper<>();
		entityWrapper.where("company_id={0}", companyId);
		entityWrapper.orderBy("dimension_date", false);
		return biLogisticAvgtimeMapper.selectList(entityWrapper);
	}

	@Override
	public List<BiShip> selectYKImproperReport(BiShip biShip) {
		return biShipMapper.selectYKImproperReport(biShip);
	}

	@Override
	public List<BiShip> selectTransNoinventoryReport(Long companyId) {
		return biShipMapper.selectTransNoinventoryReport(companyId);
	}

	@Override
	public List<BiShip> countMistakeMan() {
		return biShipMapper.countMistakeMan();
	}

	@Override
	public List<BiShip> countMistakeManByMonth() {
		return biShipMapper.countMistakeManByMonth();
	}

	@Override
	public List<BiDeliverPrescription> shippingOrderAvg() {
		EntityWrapper<BiDeliverPrescription> entityWrapper = new EntityWrapper<>();
		entityWrapper.orderBy("dimension_date", false);
		return biDeliverPrescriptionMapper.selectList(entityWrapper);
	}

}
